/**
 * @program: jvm
 * @description
 * @author: tkk fendoukaoziji
 * @create: 2019-01-25 22:14
 **/
public class StringCalNumber {
    public static void main(String[] args) {
        String result = calNumber("999", "999");
        System.out.println(result);
    }

    public static String   calNumber(String a,String b){
        StringBuilder returnStr=new StringBuilder();
        //第一步字符串反转
        StringBuilder s1=new StringBuilder();
        String cal1 = s1.append(a).reverse().toString();

        StringBuilder s2=new StringBuilder();
        String cal2=s2.append(b).reverse().toString();

        boolean overflow=false;//是否溢出
        int  overNum=0;//溢出数
        int maxLen=cal1.length()>cal2.length()?cal1.length():cal2.length();
        //第二步 把短的字符串高位补0
        if(cal1.length()>cal2.length()){
            for(int i=cal2.length();i<cal1.length();i++){
                cal2+="0";
            }
        }else{
            for(int i=cal1.length();i<cal2.length();i++){
                cal1+="0";
            }
        }
        //第三步  遍历相加，判断是否溢出  如果溢出，-10  进一位
        for (int i = 0; i <maxLen ; i++) {
            int num1=Integer.parseInt(cal1.charAt(i)+"");
            int num2=Integer.parseInt(cal2.charAt(i)+"");
            int sum=num1+num2+overNum;
            if(sum>=10){
                if(i==maxLen-1){
                    overflow=true;
                }
                overNum=1;

                returnStr.append(sum-10);

            }else{
                overNum=0;
                returnStr.append(sum);
            }
        }
        if (overflow){
            returnStr.append(overNum);
        }
        return  returnStr.reverse().toString();

    }
}
